#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;

const int maxn = 1000 + 1;
int m, n;

struct Game
{
    int t,w;
}game[maxn];

int comp(const void* p, const void* q)
{
    return ((Game*)q)->t - ((Game*)p)->t;
}

priority_queue<int> q;

int main()
{
	freopen("riddle.in","r",stdin);
	freopen("riddle.out","w",stdout);

	int total = 0;

    cin >> m >> n;
    for(int i = 0; i < n; i ++)
        cin >> game[i].t;
    for(int i = 0; i < n; i ++)
    {
        cin >> game[i].w;
        total += game[i].w;
    }

    qsort(game,n,sizeof(Game),comp);

    int j = 0;
    for(int i = n; i > 0; i --)
    {
        while(j < n && game[j].t >= i)
            q.push(game[j ++].w);
        if(!q.empty())
        {
            total -= q.top();
            q.pop();
        }
    }
    cout << m - total << endl;
	return 0;
}
